﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Restaurant.DTO;
using Restaurant.BUS;

namespace Restaurant
{
    public partial class frmNhaHang : Form
    {
        NhaHangService nhService = new NhaHangService();
        public int flag = 0;
        public bool fix = false;
        private NhaHang nh = new NhaHang();

        public NhaHang Nh
        {
            get { return nh; }
            set { nh = value; }
        }

        public frmNhaHang()
        {
            InitializeComponent();
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            if (flag == 0)
            {
                NhaHang nh = new NhaHang();
                nh.TenNH = txt_ten.Text;
                nh.Diachi = txt_diachi.Text;
                nh.Sodt = mtbSDT.Text;
                if (nhService.ThemNhaHang(nh))
                {
                    this.Close();
                    return;
                }
                MessageBox.Show("Thêm nhà hàng thất bại");
                return;
            }
            else if (flag == 1)
            {
                flag = 0;
                Nh.TenNH = txt_ten.Text;
                Nh.Diachi = txt_diachi.Text;
                Nh.Sodt = mtbSDT.Text;
                bool kq;
                if (fix)
                    kq = nhService.CapNhatNHDirtyread(nh);
                else
                    kq = nhService.CapNhatNHDirtyreadError(nh);

                if (kq)
                {
                    MessageBox.Show("Thành Công");
                    this.Close();
                    return;
                }
                else
                {
                    MessageBox.Show("Thất bại");
                    return;
                }
            }

        }

        private void btn_thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmNhaHang_Load(object sender, EventArgs e)
        {
            if (flag == 1)
            {
                txt_ten.Text = Nh.TenNH;
                txt_diachi.Text = Nh.Diachi;
                mtbSDT.Text = Nh.Sodt;
            }
        }
        private void btnChinhSua_Click(object sender, EventArgs e)
        {

        }
    }
}
